package com.rain.controller;

import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
import com.rain.enums.DateTimePatternEnum;
import com.rain.utils.DateUtil;
import com.rain.enums.PageSize;
import com.rain.query.SimplePage;
import com.rain.query.ResponseVO
import com.rain.entity.SysUser;
import com.rain.query.SysUserQuery;
import com.rain.query.PaginationResult;
import com.rain.service.SysUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
/**
 * @auther: rain
 * @description: Controller
 * @date: 2025-10-31
 */

@RestController
@RequestMapping("/sysUser")
public class SysUserController extends BaseController {

	@Resource
	private SysUserService sysUserService;

	@GetMapping
	public ResponseVO list(SysUserQuery query) {
		return getSuccessResponseVO(sysUserService.findListByPage(query));
	}

	/**
	 * 新增
	 */
	@PostMapping
	public ResponseVO add(SysUser bean) {

	return getSuccessResponseVO(sysUserService.add(bean));

	}

	/**
	 * 批量新增
	 */
	@PostMapping("/addBatch")
	public ResponseVO addBatch(List<SysUser> listBean) {

	return getSuccessResponseVO(sysUserService.addBatch(listBean));

	}

	/**
	 * 批量新增修改
	 */
	@PostMapping("/addOrUpdateBatch")
	public ResponseVO addOrUpdateBatch(List<SysUser> listBean) {

	return getSuccessResponseVO(sysUserService.addOrUpdateBatch(listBean));

	}

	/**
	 * 根据Id查询
	 */
	@GetMapping("/{id}")
	public ResponseVO getSysUserById(@PathVariable Integer id) {

		return getSuccessResponseVO(sysUserService.getSysUserById(id));

	}

	/**
	 * 根据Id更新
	 */
	@PutMapping("/{id}")
	public ResponseVO updateSysUserById(@RequestBody SysUser bean, @PathVariable Integer id){

		return getSuccessResponseVO(sysUserService.updateSysUserById(bean, id));

	}

	/**
	 * 根据Id删除
	 */
	@DeleteMapping("/{id}")
	public ResponseVO deleteSysUserById(@PathVariable Integer id) {

		return getSuccessResponseVO(sysUserService.deleteSysUserById(id));

	}

	/**
	 * 根据UsernameAndMobile查询
	 */
	@GetMapping(params = {"username", "mobile"})
	public ResponseVO getSysUserByUsernameAndMobile(@RequestParam String username, @RequestParam String mobile) {

		return getSuccessResponseVO(sysUserService.getSysUserByUsernameAndMobile(username, mobile));

	}

	/**
	 * 根据UsernameAndMobile更新
	 */
	@PutMapping(params = {"username", "mobile"})
	public ResponseVO updateSysUserByUsernameAndMobile(@RequestBody SysUser bean, @RequestParam String username, @RequestParam String mobile){

		return getSuccessResponseVO(sysUserService.updateSysUserByUsernameAndMobile(bean, username, mobile));

	}

	/**
	 * 根据UsernameAndMobile删除
	 */
	@DeleteMapping(params = {"username", "mobile"})
	public ResponseVO deleteSysUserByUsernameAndMobile(@RequestParam String username, @RequestParam String mobile) {

		return getSuccessResponseVO(sysUserService.deleteSysUserByUsernameAndMobile(username, mobile));

	}

}